vec2 fixuv(in vec2 uv){
  vec2 p=vec2(uv.x/iResolution.x*(iResolution.x/iResolution.y),abs(uv.y/iResolution.y-1.));
  return p;
}

vec3 drawGrid(in vec2 p){
  float f=floor(p.x)+floor(p.y);
  vec3 col=mix(vec3(.75),vec3(.3),smoothstep(0.,1.,mod(f,2.)));
  return col;
}

// 画中心线
vec3 drawCenterLine(in vec2 p,in vec3 col){
  p=(2.*p-iResolution.xy)/min(iResolution.x,iResolution.y);
  col=mix(col,vec3(1.,0.,0.),smoothstep(abs(p.x),abs(p.x),fwidth(p.x)*2.));
  col=mix(col,vec3(0.,0.,1.),smoothstep(abs(p.y),abs(p.y),fwidth(p.y)*2.));
  return col;
}

vec3 drawSDCricle(vec2 p,vec2 pos,float r,vec3 col,vec3 color){
  float dis=length(p-pos)-r;
   col=mix(col,color,1.-smoothstep(0.,.005,dis));
  return col;
}

vec3 drawSDBox(vec2 p,vec4 rect,vec3 col,vec3 color){
  vec2 d=p-(rect.xy+rect.zw/2.);
  // float dis = length(max(d,0.));
  float dis=length(d);
   col=mix(col,color,smoothstep(0.,0.01,dis));
  return col;
}

void mainImage(out vec4 fragColor,in vec2 fragCoord){
  vec2 p=fixuv(fragCoord);
  // p*=10.;
  vec3 col=drawGrid(p);
  col=drawCenterLine(fragCoord,col);
 
  
  // col=drawSDCricle(p,vec2(5.,5.),.5,col,vec3(1.,1.,0.));
  col=drawSDBox(p,vec4(.5,.5,.2,.2),col,vec3(1.,1.,0.));

 
  fragColor=vec4(col,1.);
}
